package com.android.demos.module.fresco.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewAdapter;
import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewHolder;
import com.android.demos.R;
import com.android.demos.data.remote.imageloader.HImageLoaderSingleton;
import com.soybean.framework.common.LogUtils;
import com.soybean.framework.imageloader.HImageConfigBuilder;
import com.soybean.framework.imageloader.HImageView;
import com.soybean.framework.imageloader.ImageLoaderCallback;

/**
 * Created on 16/8/18.
 *
 * @author aaron.huang
 * @version 1.0.0
 */
public class FrescoRecyclerAdapter extends BaseRecycleViewAdapter<FrescoRecyclerAdapter.FrescoViewHolder, String> {
    private final ImageLoaderCallback mImageLoaderCallback = new ImageLoaderCallback() {
                @Override
                public void finish(Bitmap bitmap) {
                    LogUtils.e(TAG, "width: " + bitmap.getWidth() + " height: "
                            + bitmap.getHeight() + " size: " + bitmap.getByteCount());
                }
            };
    public FrescoRecyclerAdapter(Context context) {
        super(context);
    }

    @Override
    protected FrescoViewHolder createViewHolder(ViewGroup parent) {
        View itemView = LayoutInflater.from(getContext()).inflate(R.layout.layout_fresco_recycler_item, parent, false);
        return new FrescoViewHolder(itemView);
    }

    class FrescoViewHolder extends BaseRecycleViewHolder<String> {
        private HImageView mImageView;

        public FrescoViewHolder(View itemView) {
            super(itemView);
            mImageView = (HImageView) itemView.findViewById(R.id.himageview_fresco);
        }

        @Override
        public void bindViews(String object) {
//            HImageConfig imageConfig = new HImageConfig(Uri.parse(object), mImageView);
//            imageConfig.setAutoPlayAnimations(true);
//            imageConfig.setFadeDuration(5000);
//            RoundingParams roundingParams = new RoundingParams();
//            roundingParams.setCornersRadius(60);
//            imageConfig.setRoundingParams(roundingParams);
//            imageConfig.setDefaultImage(R.color.service_phone_text);
//            HImageConfig imageConfig = new HImageConfigBuilder(mImageView, object)
//                    .setImageLoaderCallback(new ImageLoaderCallback() {
//                @Override
//                public void finish(Bitmap bitmap) {
//                    LogUtils.e(TAG, "width: " + bitmap.getWidth() + " height: "
//                            + bitmap.getHeight() + "size: " + bitmap.getByteCount());
//                }
//            }).setAutoPlayAnimations(true)
//                    .setRoundingParams(new RoundingParams().setCornersRadius(50))
//                    .setFadeDuration(300).build();
//            HImageLoaderSingleton.getInstance().loadImage(mImageView, object, mImageLoaderCallback);
            HImageLoaderSingleton.getInstance().loadImage(new HImageConfigBuilder(mImageView, object)
//                    .setRoundingParams(new RoundingParams().setCornersRadius(50))
                    .setFadeDuration(300)
                    .setAutoPlayAnimations(true)
                    .setImageLoaderCallback(mImageLoaderCallback)
                    .build());
        }
    }
}
